import { useTemplateRef } from "vue";
import PageModal from "@/components/page-modal/page-modal.vue";

function usePageModal(newCallback?: () => void, editCallback?: (itemData: any) => void) {
  const modalRef = useTemplateRef<InstanceType<typeof PageModal>>("modalRef");

  const handleNewClick = () => {
    modalRef.value?.setDialogVisible(true);
    if (newCallback) newCallback();
  };
  const handleEditClick = (itemData: any) => {
    modalRef.value?.setDialogVisible(false, itemData);
    if (editCallback) editCallback(itemData)
  };

  return {
    modalRef,
    handleNewClick,
    handleEditClick
  };
}

export default usePageModal;
